<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .wrap {
            width: 550px;
            height: 60px;
            background-color: pink;
            margin: 50px auto 0;
            border-radius: 5px;
        }
        .icon {
            width: 40px;
            height: 40px;
            float: left;
            border-radius: 50%;
            margin-top: 10px;
            margin-left: 15px;
            position: relative;
        }
        .icon img {
            width: 100%;
            height: 100%;
            position: absolute;
            border-radius: 50%;
            cursor: pointer;
            display: none;
        }
        .icon .active {
            display: block;
        }
        .content {
            width: 320px;
            height: 40px;
            float: left;
            margin-left: 25px;
            margin-top: 10px;
            display: none;
        }
        .content .text {
            width: 250px;
            height: 40px;
            outline: none;
            border: 1px solid #ccc;
            text-indent: 1em;
        }
        .content .report {
            width: 63px;
            height: 40px;
            border: 1px solid #ccc;
            outline: none;
            font-size: 14px;
            background-color: #fff;
            cursor: pointer;
        }
        .add {
            width: 60px;
            height: 40px;
            float: right;
            font-size: 25px;
            margin-top: 10px;
            margin-right: 25px;
            cursor: pointer;
        }
        ul.comment {
            width: 550px;
            margin: 30px auto;
            list-style: none;
            border-radius: 5px;
        }
        ul li {
            width: 550px;
            height: 60px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        li .pic {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-top: 10px;
            margin-left: 15px;
            float: left;
        }
        li .pic img {
            width: 100%;
            height: 100%;
            border-radius: 50%; 
        }
        li p{
            width: 470px;
            height: 40px;
            margin-top: 10px;
            margin-left: 25px;
            float: left;
            border-bottom: 1px dashed #ccc;
            line-height: 40px;
        }
    </style>
</head>
<body>
    <div class="wrap">
        <div class="icon">
            <img class="active" src="images/pic1.png" alt="">
            <img src="images/pic2.png" alt="">
        </div>
        <div class="content">
            <input type="text" class="text">
            <button class="report">发表</button>
        </div>
        <button class="add">+</button>
    </div>
    <ul class="comment">
        <!-- <li>
            <div class="pic">
                <img src="images/pic1.png" alt="">
            </div>
            <p>123</p>
        </li> -->
    </ul>
    <script>
        var add = document.getElementsByClassName('add')[0],
            content = document.getElementsByClassName('content')[0],
            imgIcons = document.querySelectorAll('.icon img'),
            report = document.getElementsByClassName('report')[0],
            text = document.getElementsByClassName('text')[0],
            imgPic = document.querySelector('.pic img'),
            pText = document.querySelector('.comment p'),
            comment = document.getElementsByClassName('comment')[0],
            imgSrc = imgIcons[0].src,
            mark = true;
            // 点击+号让文本框显示/隐藏
            add.onclick = function (){
                if(mark){
                    content.style.display = 'block';
                    mark = false;
                }else{
                    content.style.display = 'none';
                    mark = true;
                } 
            }
            //点击头像进行切换
            imgIcons[0].onclick = function(){
                this.className = '';
                imgIcons[1].className = 'active';
                imgSrc = imgIcons[1].src;
            }
            imgIcons[1].onclick = function(){
                this.className = '';
                imgIcons[0].className = 'active';
                imgSrc = imgIcons[0].src;
            }
            // 点击发表
            report.onclick = function (){
                textV = text.value;
                if(textV){
                    comment.innerHTML += `<li>        
                                        <div class="pic">
                                            <img src="${imgSrc}" alt="">
                                        </div>
                                        <p>${textV}</p>
                                    </li>`;
                                    /*或者用字符串拼接'<li><div class="pic"><img src='+imgSrc+' alt=""></div><p>'+textV+'</p></li>';*/
                    text.value = '';
                } 
            }
    </script>
</body>
</html>